package com.iwhalecloud.citybrain.flow.platform.manager.domain.model;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.enums.NextNodeParamEnum;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowNodeTempParamRepository;
import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

/**
 * @author liyang
 */
@Data
@Service
public class FlowNodeTempParamDomain implements Serializable, ApplicationContextAware {


    private static final long serialVersionUID = -7750862612450898419L;

    @Autowired
    private static FlowNodeTempParamRepository flowNodeTempParamRepository;

    /**
     * 参数编号
     */
    private Integer id;

    /**
     * 流程实例编号
     */
    @NotNull(message = "流程实例编号不能为空")
    private String processInstanceId;

    /**
     * 节点编码
     */
    @NotNull(message = "节点编码不能为空")
    private String nodeCode;

    /**
     * 参数名
     */
    @NotNull(message = "参数名不能为空")
    private String paramCode;

    /**
     * 参数值
     */
    @NotNull(message = "参数值不能为空")
    private String paramValue;

    /**
     * 参数类型
     */
    private String paramType;

    NextNodeParamEnum getParamCodeEnum() {
        return NextNodeParamEnum.valueOf(paramCode);
    }

    void save() {
        flowNodeTempParamRepository.create(this);
    }

    void update(){
        flowNodeTempParamRepository.update(this);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        flowNodeTempParamRepository = applicationContext.getBean(FlowNodeTempParamRepository.class);
    }
}